//
//  BaseNavigationController.swift
//  SinaWeiBo
//
//  Created by 有风 on 16/2/23.
//  Copyright © 2016年 YouFeng. All rights reserved.
//

import UIKit

class BaseNavigationController: UINavigationController, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        let count = childViewControllers.count
        
        if count != 0 {
            viewController.hidesBottomBarWhenPushed = true
        
        
        let btn = UIButton(backImageName: nil, title: "返回", textColor: UIColor.blackColor(), imageName: "navigationbar_back_withtext", fontSize: 14)
        btn.addTarget(self, action: "back", forControlEvents: .TouchUpInside)
        
        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        }
        super.pushViewController(viewController, animated: true)
        
    }
    
    @objc private func back() {
        self.popViewControllerAnimated(true)
    }
    
    
     func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return childViewControllers.count > 1
    }
    
}
